from functools import partial
# import androidhelper
from def_pack.clip_board_handle import setclip_board


def helloCallBack(aa,clsdoc,event):
    clsdoc.gloco(aa)
    return "break"
    # droid = androidhelper.Android()
    # droid.setClipboard(aa)
    # fo = open(copyfind_find, "a+", encoding='utf-8')
    # fo.write(aa)
    # fo.close()
def helloCallBack_list(aa,event):
    setclip_board(aa)
    # clsdoc.gloco(aa, event)
    return "break"

def show_arrow_cursor(hhs,textframe,event):
    # global textframe
    # global tkinter
    # textframe.config(cursor='arrow')
    # textframe.tag_config(f"txtform{hhs}",font=("等线", 13),background="LightGoldenrodYellow", foreground="Black")
    textframe.tag_config(f"txtform{hhs}",background="LightGoldenrodYellow")
    return "break"

    #这个三维效果，对btn才有用
    # textframe.tag_config(f"txtform{hhs}",relief = "sunken")


def show_xterm_cursor(hhs,textframe,event):
    # global textframe
    # textframe.config(cursor='xterm')
    # textframe.tag_config(f"txtform{hhs}", font=("等线", 13),background="White", foreground="Black")
    textframe.tag_config(f"txtform{hhs}",background="White")
    return "break"

#这是序列显示文本的可封装的内容
def tag_textframe_handle(textframe,tag_name,hhs,command_func):
    textframe.tag_config(tag_name, font=("等线", 13), selectbackground="white", foreground="Black")
    textframe.tag_bind(tag_name, '<Enter>', partial(show_arrow_cursor, hhs, textframe))
    # textframe.tag_bind('link', '<Leave>', show_xterm_cursor)
    textframe.tag_bind(tag_name, '<Leave>', partial(show_xterm_cursor, hhs, textframe))
    # textframe.tag_bind(f"txtform{hhs}", '<Button-1>', partial(lambda event:helloCallBack(nn)))
    textframe.tag_bind(tag_name, '<Button-1>', command_func)


def add_str(list1,textframe,clsdoc):


    hhs=1
    dh="\n\n"
    for nn in list1:

        textframe.insert('insert ', f'      {nn}{dh}')



        textframe.tag_add(f"txtform{hhs}", f"{hhs}.0", f"{hhs}.end")
        tag_textframe_handle(textframe, f"txtform{hhs}", hhs, partial(helloCallBack,nn,clsdoc))
        # textframe.tag_config(f"txtform{hhs}", font=("等线", 13),selectbackground="white",foreground="Black")
        # textframe.tag_bind(f"txtform{hhs}", '<Enter>', partial(show_arrow_cursor,hhs,textframe))
        # # textframe.tag_bind('link', '<Leave>', show_xterm_cursor)
        # textframe.tag_bind(f"txtform{hhs}", '<Leave>', partial(show_xterm_cursor,hhs,textframe))
        # # textframe.tag_bind(f"txtform{hhs}", '<Button-1>', partial(lambda event:helloCallBack(nn)))
        # textframe.tag_bind(f"txtform{hhs}", '<Button-1>', partial(helloCallBack,nn,clsdoc))
        # '微软雅黑(常规)'
                             # 'bold',background="yellow", foreground="blue", underline=1)
        # textframe.insert('insert ', f'')
        hhs=hhs+2
def add_list_num(list1,textframe,line_numstr):
    hhs = 1
    dh = "\n\n"
    hhsa=1
    count = 0
    cc = 6
    # print(list1)
    for pp in range(len(list1)):

        # for uy in range(int(line_numstr)):


        nn=list1[pp]
        # textframe.insert('insert ', f'{nn}  ')
        if count == 0:
            textframe.insert('insert', f'      {nn}  ')
        else:
            textframe.insert('insert', f'{nn}  ')
        # if count==0:
        #     textframe.tag_add(f"txtform{hhsa}", f"{hhs}.{cc}", f"{hhs}.{len(nn)}")
        #     cc=len(nn)
        # else:
        textframe.tag_add(f"txtform{hhsa}", f"{hhs}.{int(cc)}", f"{hhs}.{int(cc)+len(nn)}")
        cc = cc+len(nn)+2
        textframe.tag_config(f"txtform{hhsa}", font=("等线", 13), selectbackground="white", foreground="Black")
        textframe.tag_bind(f"txtform{hhsa}", '<Enter>', partial(show_arrow_cursor, hhsa, textframe))
        # textframe.tag_bind('link', '<Leave>', show_xterm_cursor)
        textframe.tag_bind(f"txtform{hhsa}", '<Leave>', partial(show_xterm_cursor, hhsa, textframe))
        # textframe.tag_bind(f"txtform{hhs}", '<Button-1>', partial(lambda event:helloCallBack(nn)))
        textframe.tag_bind(f"txtform{hhsa}", '<Button-1>', partial(helloCallBack_list, nn))
        # '微软雅黑(常规)'
        # 'bold',background="yellow", foreground="blue", underline=1)
        # textframe.insert('insert ', f'')
        hhsa=hhsa+1
        count = count+1
        if count==line_numstr:
            textframe.insert('insert', f'{dh}')
            hhs = hhs + 2
            count=0
            cc = 6


    pass

def add_dict_num(dict1,textframe,line_numstr):
    hhs = 1
    dh = "\n\n"
    hhsa=1
    count = 0
    cc = 5
    toole=len(dict1.keys())
    # for pp in range(len(list1)):
    # for pp in range(toole):
    for pp in dict1.keys():
        values=dict1.get(str(pp))


        # for uy in range(int(line_numstr)):


        nn=f"{values}({pp})"
        if count == 0:
            textframe.insert('insert ', f'      {nn}  ')
        else:
            textframe.insert('insert ', f'{nn}  ')
        # if count==0:
        #     textframe.tag_add(f"txtform{hhsa}", f"{hhs}.{cc}", f"{hhs}.{len(nn)}")
        #     cc=len(nn)
        # else:
        textframe.tag_add(f"txtform{hhsa}", f"{hhs}.{int(cc)}", f"{hhs}.{int(cc)+len(nn)}")
        cc = cc+len(nn)+2
        textframe.tag_config(f"txtform{hhsa}", font=("等线", 13), selectbackground="white", foreground="Black")
        textframe.tag_bind(f"txtform{hhsa}", '<Enter>', partial(show_arrow_cursor, hhsa, textframe))
        # textframe.tag_bind('link', '<Leave>', show_xterm_cursor)
        textframe.tag_bind(f"txtform{hhsa}", '<Leave>', partial(show_xterm_cursor, hhsa, textframe))
        # textframe.tag_bind(f"txtform{hhs}", '<Button-1>', partial(lambda event:helloCallBack(nn)))
        textframe.tag_bind(f"txtform{hhsa}", '<Button-1>', partial(helloCallBack_list, pp))
        # '微软雅黑(常规)'
        # 'bold',background="yellow", foreground="blue", underline=1)
        # textframe.insert('insert ', f'')
        hhsa=hhsa+1
        count = count+1
        if count==line_numstr:
            textframe.insert('insert ', f'{dh}')
            hhs = hhs + 2
            count=0
            cc = 5


    pass

if __name__ == '__main__':
    pass